;$(function() {
	var lid = $('#lid');
	var username = $('#username');
	var password = $('#password');
	var qq = $('#qq');
	var tp = $("#telphone");
	
	var xl = $("#xiaoliang");
	var fh = $("#fenhong");
	$('#navDiv').find('a').each(function(i, element) {
		var $element = $(element);
		var index = parseInt($(element).attr('data-index'));
		if (4 === index) {
			$element.addClass('on');
		} else {
			$element.removeClass('on');
		}
	});
	$("#addPerple").click(function(){
		$("#addDiv").slideToggle();
	});
	$("#state").find('.cs-placeholder').click(function(){
		$("#state").addClass("cs-active");
	});
	$("#model").find('.cs-placeholder').click(function(){
		$("#model").addClass("cs-active");
	});
	$("#sureAdd").click(function(){
		$.ajax({
			url: '/lottery/rest/user/checkName',
			type: 'POST',
			dataType: 'json',
			data: {userName:username.val()},
			error: function(err) {
				console.log(err);
				alert('请求失败，请重试');
			},
			success: function(res) {
				var code = res.status;
				var type = $("input[name='mantype']:checked").val();
				if(type == '1'){
					type = 'agent';
				}else{
					type = 'player';
				};
				var data = {
						userName: username.val(),
						password: $.md5(password.val()),
						role:type
					};
				if(code == '00'){
					$.ajax({
						url: '/lottery/rest/user/add',
						type: 'POST',
						cache: false,
						dataType: 'json',
						//data: {username: username.val(), password: $.md5(password.val()),qq:qq.val(),mobile:tp.val(),role:type,xl:xl.val(),fh:fh.val()},
						data:data,
						error: function(err) {
							alert('请求失败，请重试');
							console.log(err);
						},
						success: function(res) {
							var code = res.status;
							var msg = res.errorMsg;
							if (code == '00') {
								alert('新增成功');
							}else{
								alert(msg);
							}
						},
					});
				}else{
					alert('用户名已存在');
					return;
				}
			},
		})
	});
	$("body").on('click','.QXGD',function(){
		$("#GD").fadeOut();
	})
	$("body").on('click','.QXZZ',function(){
		$("#ZZ").fadeOut();
	})
	$("body").on('click','.icon-exchange',function(){
		$("#ZZ").fadeIn();
	});
	$("body").on('click','.icon-pencil-squared',function(){
		$("#GD").fadeIn();
	});
	$("body").on('click','.YK',function(){
		$("#two").fadeOut();
		
	});
	var name = window.getUrl.geturlset('username');
	if(!name){
		console.log('aa');
	}else{
	var	data = {
		
		}
	}
});
function stateFun(e){
	var e=window.event||e;
	e = e.srcElement||e.target; 
	if(e.nodeName == 'SPAN'){
		var val = $(e).parent().attr('data-value');
		var text = $(e).text();
		$("#state").attr('data-index',val);
		$("#state").find('.cs-placeholder').text(text);
	};
	$("#state").removeClass('cs-active');
};
function modelFun(e){
	var e=window.event||e;
	e = e.srcElement||e.target; 
	if(e.nodeName == 'SPAN'){
		var val = $(e).parent().attr('data-value');
		var text = $(e).text();
		$("#model").attr('data-index',val);
		$("#model").find('.cs-placeholder').text(text);
	};
	$("#model").removeClass('cs-active');
};